// pages/brief/brief.js
var util = require('../../utils/util.js')
var WxParse = require('../../wxParse/wxParse.js')
var app = getApp()
var flag = false
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uncontentst:false, //暂无数据 false 默认不显示
		actionid:"",
		title:"",
    article_content:'',//定义内容的变量
		haveinfo:"",
		noinfo: "",
    ifRefresh: false,	//是否是下拉刷新
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({ actionid: options.aid });
    //请求数据
    that.requestinfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
	  app.publicchangenavigate()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this
    wx.showNavigationBarLoading() //在标题栏中显示加载
    //初始化参数
    that.setData({
      ifRefresh: true,
    })
    //模拟加载
    setTimeout(function () {
      //请求数据
      that.requestinfo()
    }, 1000);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
	return app.globalshare();
  },
  //请求信息
  requestinfo:function(){
    var that = this
    //发起网络请求
    util.AJAX('Home/Index/getInfoPublic', { aid: that.data.actionid }, function (res) { //方法体
      if (res.data.StatusCode == 100) {  //更新成功
        var temp = WxParse.wxParse('article_content', 'html', res.data.Info.content, that, 5);
        that.setData({
          uncontentst: false,
          title: res.data.Info.name,
          article_content: temp,
          haveinfo: true,
          noinfo: false
        })
      } else {
        that.setData({
          uncontentst: true,
          title: null,
          article_content: '',
          haveinfo: false,
          noinfo: false
        })
      }

      //判断并关闭下拉刷新
      if (that.data.ifRefresh) {
        that.setData({ ifRefresh: false })
        // complete
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      }
    }, 'POST')
  }
})